<template>
  <div class="Comment">
    <!-- 按钮 -->
    <div class="btns">
     
      <el-form size="small" inline  style="text-align:right">
             <br>
        <el-form-item label="内容">
          <el-input v-model="param.content"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button size="small" type="primary"  @click="loadcomment" icon="el-icon-search" plain>搜索</el-button>
          <el-button type="primary" size="small" @click="toAddHandler" plain><i class="el-icon-edit"> 新增</i></el-button>
        </el-form-item>

       
      </el-form>
      
       <div style="text-align:right">
       <el-button size= "small" type="warning" round  @click="downloadHandler">导出</el-button>
      </div>
  </div>

    <!-- /按钮 -->
    <!-- {{comments}}  -->
    <!-- 表格 -->

        <br/>
    <el-table :data="Comment" border="ture">
      <el-table-column type="index" :index="1" label="序号" align="center" width="100"></el-table-column>
      <el-table-column label="内容" prop="content" align="center" width="250"></el-table-column>
      <el-table-column label="楼层" prop="floor" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="用户ID" prop="userId" align="center"></el-table-column>
      <el-table-column label="文章ID" prop="articleId" align="center"></el-table-column>
      <el-table-column label="回复ID" prop="parentId" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="primary" plain size="mini" icon="el-icon-edit" @click="updateHandler(scope.row)">修改</el-button>
           <br>

          <el-button type="danger" plain size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)">删除</el-button>
        </template>
      </el-table-column>

      <!-- /定制插槽 -->
    </el-table>
    <!-- /表格 -->
  </div>
</template>

<script>
import { get, del } from "@/utils/request";
export default {
  // 组件名称
  name: "demo",
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值

  //页面数据
  data() {
    return {
      //参数，用于保存检索的参数
      param: {},
      //组件模板中需要的数据
      Comment: []
    };
  },
  //页面渲染的时候会调用的函数
  created() {
    this.loadcomment();
  },
  //所有的方法
  methods: {
//导出
     downloadHandler(){
      window.location.href = "http://8.131.68.179:9999/cms_comment/download?name="+this.param.name
    },
    //修改事件处理函数
    updateHandler(row) {
      //跳转到修改页面（新增页面）
      //跳转携带当前行的数据
      this.$router.push({
        path: "/Comment/create", //跳转的路径（前端）
        query: row //携带的参数
      });
    },
    //删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let url = "http://8.131.68.179:9999/cms_comment/deleteByID";
        del(url, { id: row.id }).then(resp => {
          this.$message({ type: "success", message: resp.message });
          this.loadcomment();
        });
      });
    },

    //跳转
    toAddHandler() {
      this.$router.push("/Comment/create");
    },
    //查询后台中的信息
    loadcomment() {
      let url = "http://8.131.68.179:9999/cms_comment/query";
      get(url, this.param).then(resp => {
        this.Comment = resp.data;
      });
    }
  }
};
</script>

<style scoped>
  .el-form {
    background:#0db66f;
  }

</style>
